package com.ransj.iphone;

import com.ransj.iphone.utils.IUtils;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;

public class MainActivity extends Activity {
	public static final String COMMAND_FILE = "iphone";
	private View m_vHelp;
	private View m_vVibrate;
	private View m_vUninstall;
	private View m_vAbout;
	private View m_vRoot;
	private View m_vStart;
	private CheckBox m_cbVibrate;
	private TextView m_tvVersion;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.page_setting);
		m_vHelp = findViewById(R.id.page_setting_help);
		m_vVibrate = findViewById(R.id.page_setting_vibrate);
		m_cbVibrate = (CheckBox) findViewById(R.id.page_setting_vibrate_cb);
		m_vUninstall = findViewById(R.id.page_setting_uninstall);
		m_vAbout = findViewById(R.id.page_setting_about);
		m_vRoot = findViewById(R.id.page_setting_root);
		m_tvVersion = (TextView) findViewById(R.id.page_setting_version_tv);
		m_vStart = findViewById(R.id.page_setting_start);
		OnClickListener listener = new OnClickListener() {

			@Override
			public void onClick(View v) {
				switch (v.getId()) {
				case R.id.page_setting_uninstall:
					jumpHelp(IConstants.URL_UNINSTALL);
					break;
				case R.id.page_setting_about:
					jumpHelp(IConstants.URL_ABOUT);
					break;
				case R.id.page_setting_root:
					jumpHelp(IConstants.URL_ROOT);
					break;
				case R.id.page_setting_start:
					startIphoneService();
					break;
				}
			}
		};
		m_vHelp.setOnClickListener(listener);
		m_vVibrate.setOnClickListener(listener);
		m_vUninstall.setOnClickListener(listener);
		m_vAbout.setOnClickListener(listener);
		m_vRoot.setOnClickListener(listener);
		m_vStart.setOnClickListener(listener);
		m_cbVibrate.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
			}
		});
		m_tvVersion.setText(IUtils.getVersionCode(this, getPackageManager()));
	}
	
	private void startIphoneService(){
		Intent service = new Intent(this, Iservice.class);
		startService(service);
	}
	
	private void jumpHelp(String url){
		Intent help = new Intent(this, PageHelp.class);
		help.putExtra(IConstants.KEY_HLEP_URL, url);
		startActivity(help);
	}
}
